package cn.youth996.springcloud.controller;

import cn.youth996.springcloud.entities.CommonResult;
import cn.youth996.springcloud.entities.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @author Zhan Xinjian
 * @date 2021/3/5
 */
@RequestMapping("/order")
@RestController
@Slf4j
public class OrderController {
    private static final String PAYMENT_URL = "http://localhost:8000";
    @Resource
    private RestTemplate restTemplate;

    @GetMapping("/payment/save")
    public CommonResult save(Payment payment) {
        return restTemplate.postForObject(PAYMENT_URL+"/payment/save" , payment, CommonResult.class);
    }

    @GetMapping("/payment/get/{id}")
    public CommonResult getPaymentById(@PathVariable("id") Long id) {
        return restTemplate.getForObject(PAYMENT_URL + "payment/get/"+id, CommonResult.class);
    }
}
